package com.example.vueAPI.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.example.vueAPI.service.IUserService;
import com.example.vueAPI.entity.User;

import org.springframework.web.bind.annotation.RestController;

/**
 *  前端控制器
 *
 * @author myk
 * @since 2024-11-11
 */
@RestController
@RequestMapping("/admin/user")
@Tag(name = "接口")
        public class UserController {
    
@Resource
private IUserService userService;

// 新增或者更新
@PostMapping("/add")
@Operation(summary = "新增或者修改")
public boolean save(@RequestBody User user){
        return userService.saveOrUpdate(user);
        }

@DeleteMapping("/{id}")
@Operation(summary = "根据id删除")
public Boolean delete(@PathVariable Integer id){
        return userService.removeById(id);
        }

@PostMapping("/del/batch")
@Operation(summary = "批量删除")
public boolean deleteBatch(@RequestBody List<Integer> ids){
        return userService.removeByIds(ids);
        }

@GetMapping
@Operation(summary = "查询全部")
public List<User> findAll(){
        return userService.list();
        }

@GetMapping("/{id}")
@Operation(summary = "根据id查询")
public User findOne(@PathVariable Integer id){
        return userService.getById(id);
        }

@GetMapping("/page")
@Operation(summary = "分页查询")
public Page<User> findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return userService.page(new Page<>(pageNum,pageSize),queryWrapper);
        }

        }

